package org.jetlinks.pro.network;

import org.jetlinks.core.metadata.ConfigMetadata;
import reactor.core.publisher.Mono;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * 输入描述.
 *
 * @author zhangji
 * @version 1.11 2021/10/26
 */
public class NetworkTestUtils {
    public static NetworkProvider<NetworkProperties> createNetworkProvider() {
        return new NetworkProvider<NetworkProperties>() {
            @Nonnull
            @Override
            public NetworkType getType() {
                return DefaultNetworkType.HTTP_CLIENT;
            }

            @Nonnull
            @Override
            public Network createNetwork(@Nonnull NetworkProperties properties) {
                return new Network() {
                    @Override
                    public String getId() {
                        return properties.getId();
                    }

                    @Override
                    public NetworkType getType() {
                        return DefaultNetworkType.HTTP_CLIENT;
                    }

                    @Override
                    public void shutdown() {

                    }

                    @Override
                    public boolean isAlive() {
                        return false;
                    }

                    @Override
                    public boolean isAutoReload() {
                        return true;
                    }
                };
            }

            @Override
            public void reload(@Nonnull Network network,
                               @Nonnull NetworkProperties properties) {

            }

            @Nullable
            @Override
            public ConfigMetadata getConfigMetadata() {
                return null;
            }

            @Nonnull
            @Override
            public Mono<NetworkProperties> createConfig(@Nonnull NetworkProperties properties) {
                return Mono.just(properties);
            }
        };
    }
}
